package com.project.movie.logging;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

@Aspect
public class Logger {

    private final org.slf4j.Logger log = LoggerFactory.getLogger(this.getClass());

    @Pointcut("within(com.project.movie.controllers..*)"+"|| within(com.project.movie.dao..*)")
    public void definePointcuts(){

    }

    @Before("definePointcuts()")
    public void logBefore(JoinPoint joinPoint){
        log.debug("\n");
        log.debug("-------------前--------------");
        log.debug(
                "输入参数",
                joinPoint.getSignature().getDeclaringType(),
                joinPoint.getSignature().getName(),
                Arrays.toString(joinPoint.getArgs())
        );
        log.debug("-------------------------------");
        log.debug("\n");
    }

    @After("definePointcuts()")
    public void logAfter(JoinPoint joinPoint){
        log.debug("\n");
        log.debug("---------------后----------------");
        log.debug(
                "输入参数",
                joinPoint.getSignature().getDeclaringType(),
                joinPoint.getSignature().getName(),
                Arrays.toString(joinPoint.getArgs())
        );
        log.debug("---------------------------------");
        log.debug("\n");
    }
}
